package com.pet.server.ext.action.user;

import java.util.List;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.pet.server.ext.ActionBase;
import com.pet.server.ext.ApiError;
import com.pet.server.ext.Result;
import com.pet.server.ext.data.PetInfo;
import com.pet.server.ext.service.UserService;
import com.pet.server.ext.util.JsonUtil;
import com.pet.server.ext.util.Parameters;
import com.pet.server.ext.util.cache.ConstantUtil;

public class Petlist extends ActionBase{
	
	public String userName,password;
	
	public Petlist(){
		 needCheckAuth =true;
	}
	
	@Override
	public void initParameters(Parameters params) throws ApiError {	
		
	}
	
	@Override
	public Result invokeService() throws ApiError {
		
		UserService userService = new UserService();
		List<PetInfo> list = userService.queryPetInfoByUserId(user.user_id);
		JSONObject data = new JSONObject();
		JSONArray listJson = new JSONArray();
		for(PetInfo pet:list){
			JSONObject o = new JSONObject();
			o.put("pet_id", pet.pet_id);
			o.put("name", pet.pet_name);
			o.put("ico_path", pet.ico_path);
			o.put("breed", pet.breed);
			o.put("breed_name", ConstantUtil.getInstance().getName(pet.breed));
			o.put("pet_cate", pet.pet_cate);
			o.put("birthday",JsonUtil.getTime(pet.create_time));
			listJson.add(o);
		}
		data.accumulate("list", listJson);
		Result result = new Result();
		result.put("data", data);
	    return result;
	}
}
